<?php
$query = mysqli_query($connect, "select * from msg order by id desc");

if (!$query) exit;

$data = array();

while ($item = mysqli_fetch_assoc($query)) {

    $data[] = $item;
    
}
